﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using SmartSpace.UI.Silverlight.Dynamic.DynamicRef;

namespace SmartSpace.UI.Silverlight.Dynamic.Controls
{
    /// <summary>
    /// 文本框控件
    /// </summary>
    public partial class TextControl : PMFDataControl
    {
        public TextControl()
        {
            InitializeComponent();   
        }

        #region Overrides

        public override void UpdateSource()
        {
            DataSource.Value = m_txtName.Text;
            DataSource.Text = DataSource.Value;

            this.GetBindingExpression(PMFDataControl.DataSourceProperty).UpdateSource();
        }

        protected override void OnIsReadOnlyChanged(bool isReadOnly)
        {
            if (isReadOnly)
            {
                m_txtName.IsReadOnly = true;
            }
            else
            {
                m_txtName.IsReadOnly = false;
            }
        }

        protected override void OnDataSourceChanged(FieldInstance dataSource)
        {
            if (!string.IsNullOrEmpty(DataSource.Text))
            {
                m_txtName.Text = DataSource.Text;
            }
        }

        #endregion

        public TextWrapping TextWrapping
        {
            get
            {
                return m_txtName.TextWrapping;
            }
            set
            {
                m_txtName.TextWrapping = value;
            }
        }

        public bool AcceptsReturn
        {
            get
            {
                return m_txtName.AcceptsReturn;
            }
            set
            {
                m_txtName.AcceptsReturn = true;
            }
        }
    }
}
